import axios from "axios";

//获取blog相关数据内容
export async function getBlogLists({ page = 1, limit = 10, categoryId = -1 }) {
    return axios.get('/api/blog', {
        params: {
            page,
            limit,
            categoryId
        }
    }).then(res => res.data.data)
}

//获取所有文章分类
export async function getBlogType() {
    return axios.get("/api/blogtype").then(res => res.data.data)
}

// 获取文章详情
export async function getByBlogId(id) {
    return axios.get(`/api/blog/${id}`).then(res => res.data.data);
}

// 分页获取文章评论
export async function getByCategoryIdMessage({ page = 1, limit = 5, blogid = "" }) {
    return axios.get('/api/comment', {
        params: {
            page,
            limit,
            blogid
        }
    }).then(res => res.data.data);
}

// 添加文章评论
/**
 * blogId,
 * nickname,
 * content
 */
export async function addCategoryIdComment(params) {
    return axios.post('/api/comment', params).then(res => res.data.data);
}

// 更新文章
export async function updateByIdBlogs(id, params) {
    return axios.put(`/api/blog/${id}`, params).then(res => res.data);
}